/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
import React, { useEffect, useState } from "react";
import { Button, Space, Table, Tag } from "antd";
import type { ColumnsType } from "antd/es/table";
import { CategoryType } from "@/types/pro";
import { categoryGet } from "@/api/pro";

const columns: ColumnsType<CategoryType> = [
  {
    title: "类目层级",
    dataIndex: "level",
    key: "level",
    render: (level, record, index) => {
      let lvArr = ["", "一级", "二级类目", "三级类目"];
      return lvArr[level];
    },
  },
  {
    title: "分类名称",
    dataIndex: "name",
    key: "name",
  },
  {
    title: "父级id",
    dataIndex: "parent_id",
    key: "parent_id",
  },
  {
    title: "操作",
    key: "action",
    render: (_, record) => (
      <Space size="middle">
        <Button type="primary" size="small">
          编辑
        </Button>
        <Button type="primary" size="small" danger>
          删除
        </Button>
      </Space>
    ),
  },
];

// const data: CategoryType[] = [
//   {
//     objectId: "sss",
//     level: 1,
//     name: "开发",
//     icon: "img.png",
//     parent_id: "123",
//     grandparent_id: "456",
//   },
// ];

const CateList: React.FC = () => {
  let [data, setData] = useState<CategoryType[]>([]);
  useEffect(() => {
    categoryGet().then((res) => {
      setData(res.data.results);
    });
  }, []);
  return <Table columns={columns} dataSource={data} rowKey="objectId" />;
};

export default CateList;
